package com.hongdee.crm.carConfig.dao.impl;

import com.hongdee.base.basedao.impl.BaseDaoImpl;
import com.hongdee.crm.carConfig.dao.ITCrmCarWarrantyDao;
import com.hongdee.crm.carConfig.entity.TCrmCarWarranty;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by My on 2017/3/30.
 */
@Component
public class TCrmCarWarrantyDaoImpl extends BaseDaoImpl implements ITCrmCarWarrantyDao {


    @Override
    public TCrmCarWarranty findCarZbInfo(String code) throws Exception {
        Map<String,Object> map=new HashMap<>();
        map.put("code",code);
        return (TCrmCarWarranty) this.getHibernateDao().findEntityByHqlWithParams(
                "from TCrmCarWarranty where code=:code order by dispOrder ",map);
    }

    @Override
    public List<TCrmCarWarranty> findParamByPCodeList(String pCode) throws Exception {
        Map<String,Object> map=new HashMap<>();
        map.put("pCode",pCode);
        return this.getHibernateDao().findEntityListByHqlWithParams("from TCrmCarWarranty where pCode=:pCode order by dispOrder",map);
    }

    @Override
    public List<Map<String, Object>> childList(String sql,String key) throws Exception{

        return this.getJdbcDao().queryForMapListBySqlWithParams(sql,key,key);
    }

    @Override
    public boolean checkChild(String pCode,String code,String id) throws Exception {
        String sqlStr="select * from t_crm_car_warranty where p_code=? and `code`=? ";
        List<String> paramList=new ArrayList<>();
        paramList.add(pCode);
        paramList.add(code);
        if(id!=null || !"".equals(id)){
            sqlStr+=" and id <>? ";
            paramList.add(id);
        }
        List<Map<String,Object>> list=this.getJdbcDao().queryForMapListBySqlWithParams(sqlStr,paramList.toArray());
        if(list!=null){
            if(list.size()>0){
                return false;
            }
        }
        return true;
    }

}
